{% load shop_currency %}
{% load url_parameters %}
{% load threadedcommentstags %}

<div id="sort">
    <p>Sort by:</p>
    <ul>
        {% if sort == 'name' %}
            <li><a class="selected" href="{% add_get_parameter sort='name_reverse' %}">name</a></li>
        {% else %}
            {% if sort == 'name_reverse' %}
                <li><a class="selected" href="{% add_get_parameter sort='name' %}">name</a></li>
            {% else %}
                <li><a href="{% add_get_parameter sort='name' %}">name</a></li>
            {% endif %}
        {% endif %}

        {% if sort == 'rating' %}
            <li><a class="selected" href="{% add_get_parameter sort='rating_reverse' %}">rating</a></li>
        {% else %}
            {% if sort == 'rating_reverse' %}
                <li><a class="selected" href="{% add_get_parameter sort='rating' %}">rating</a></li>
            {% else %}
                <li><a href="{% add_get_parameter sort='rating' %}">rating</a></li>
            {% endif %}
        {% endif %}

        {% if sort == 'price' %}
            <li><a class="selected" href="{% add_get_parameter sort='price_reverse' %}">price</a></li>
        {% else %}
            {% if sort == 'price_reverse' %}
                <li><a class="selected" href="{% add_get_parameter sort='price' %}">price</a></li>
            {% else %}
                <li><a href="{% add_get_parameter sort='price' %}">price</a></li>
            {% endif %}
        {% endif %}
    </ul>
</div>

<div id="product-list">
<ul id="products-listing">
{%  for product in products.object_list %}
    <li>
        <h3><a href="{% url shop.views.product.detail product.id %}">{{ product.name }}</a></h3>

        <p class="excerpt">{{ product.description|truncatewords:40 }}</p>
        <p class="price">{{ product.price|currency }}</p>
        <p class="stock">
            {% if product.stock > 0 %}
                {{ product.stock }} in stock
            {% else %}
                <span class="zero">Out of stock</span>
            {% endif %}
        </p>
        <p class="comments">{{ product.comment_count }} comment{{ product.comment_count|pluralize }}</p>
        {% include "ratings.html" %}
        <form class="buy" method="post" action="{% url shop.views.cart.add product.id %}">
            {% csrf_token %}
            <div><input type="submit" value="Add to Cart"/></div>
            <div><input type="hidden" name="next" value="{{ request.get_full_path }}"/></div>
        </form>
    </li>
{%  endfor %}
</ul>
</div>

{% include "product_paging.html" %}
